package com.goldsprite.gameframeworks.ruletilemap.core;

import java.util.HashMap;
import java.util.Map;

public abstract class BaseMapRenderer {
	protected int tileSize = 16;
	protected Map<String, Object> iconMapping = new HashMap<>();

	public abstract void initializeIcons(Map<String, Object> iconMap);
	public abstract void renderMap(String mapData);
	public abstract void dispose();

	// 通用方法
	public int getTileSize() { return tileSize; }
	public void setTileSize(int tileSize) { this.tileSize = tileSize; }

	protected String[][] parseMapToGrid(String mapData) {
		String[] rows = mapData.split("\n");
		int height = rows.length;
		int width = rows[0].trim().split(" +").length;

		String[][] grid = new String[height][width];
		for (int y = 0; y < height; y++) {
			String[] cells = rows[y].trim().split(" +");
			for (int x = 0; x < width; x++) {
				grid[y][x] = cells[x];
			}
		}
		return grid;
	}
}
